"use strict";

define(function() {
    var _ = {};

    _.get_json = function(url, ok, fail) {
        // prepare callbacks
        var req = new XMLHttpRequest();
        req.onload = function() {
            var json = req.response;
            if (json == null) json = { error: "internal error" };
            if (json.error != null) fail(json.error);
            else ok(json.result);
        };
        req.onabort = function() { fail("abort"); };
        req.onerror = function() { fail("error"); };

        // fire!
        req.responseType = 'json';
        req.open('GET', url);
        req.send();
    };

    return _;
});

